home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86b.arc / NUMBERS.DOC < prev    next >
Encoding:
Text File  |  1986-06-23  |  3.8 KB  |  80 lines

  1. ---NUMBERS.DOC---
  2.  
  3. Numbers and Bases
  4.  
  5. A86 supports a variety of formats for numbers.  In non-computer life, we
  6. write numbers in a decimal format.  There are ten digits, 0 through 9, that
  7. we use to describe numbers; and each digit-position is ten times as
  8. significant as the position to its right.   The number ten is called the
  9. "base" of the decimal format.  Computer programmers often find it convenient to
  10. use other bases to specify numbers used in their programs.  The most commonly-
  11. used bases are two (binary format), sixteen (hexadecimal format), and eight
  12. (octal format).
  13.  
  14. The hexadecimal format requires sixteen digits.  The extra six digits beyond
  15. 0 through 9 are denoted by the first six letters of the alphabet: A for ten,
  16. B for eleven, C for twelve, D for thirteen, E for fourteen, and F for fifteen.
  17.  
  18. In A86, a number must always begin with a digit from 0 through 9, even if the
  19. base is hexadecimal.  This is so that A86 can distinguish between a number and
  20. a symbol that happens to have digits in its name.  If a hexadecimal number
  21. would begin with a letter, you precede the letter with a zero.  For example,
  22. hex A0, which is the same as decimal 160, would be written 0A0.
  23.  
  24. Because it is necessary for you to append leading zeroes to many hex numbers,
  25. and because you never have to do so for decimal numbers, I decided to make
  26. hexadecimal the default base for numbers with leading zeroes.  Decimal is still
  27. the default base for numbers beginning with 1 through 9.
  28.  
  29. The default base can be overridden, with a letter or letters at the end of the
  30. number: B or xB for binary, O or Q for octal, H for hexadecimal, and D or xD for
  31. decimal.  Examples:
  32.  
  33.     077Q      octal, value is 8*7 + 7 = 63 in decimal notation
  34.     123O      octal, if that last "O" is a letter: 64 + 2*8 + 3 = 83 decimal
  35.     1230      decimal 1230, illustrating why you should use "Q" for octal!!
  36.     100D      superfluous D indicates decimal base
  37.     0100D     hexadecimal number 100D, which is 4096 + 13 = 5009 in decimal
  38.     0100xD    decimal 100, since the xD overrides the default hex-format
  39.     0110B     hexadecimal 110B, which is 4096 + 256 + 11 = 5263 in decimal
  40.     0110xB    binary 4+2 = 6 in decimal notation
  41.     110B      also binary 4+2 = 6, since "B" is not a decimal-digit
  42.  
  43. The last five examples above illustrate why an "x" is sometimes necessary
  44. before the base-override letter "B" or "D".  If that letter can be interpreted
  45. as a hex digit, it is; the "x" forces an override-interpretation for the "B"
  46. or "D".  By the way, the usage of lower-case for x and upper-case for the
  47. following override-letter is simply a recommendation; A86 always treats upper-
  48. and lower-case letters equivalently.
  49.  
  50.  
  51. The RADIX Directive
  52.  
  53. The above-mentioned set of defaults (hex if leading zero, decimal otherwise)
  54. can be overridden with the RADIX directive.  The RADIX directive consists of the
  55. word RADIX followed by a number from 2 to 16.  The default base for the number
  56. is ALWAYS decimal, regardless of any (or no) previous RADIX commands.  The
  57. number gives the default base for ALL subsequent numbers, up to (but not
  58. including) the next RADIX command.  If there is no number following RADIX, then
  59. A86 returns to its initial mixed-default of hex for leading zeroes, decimal for
  60. other leading digits.
  61.  
  62. For compatibility with IBM's assembler, RADIX can appear with a leading period;
  63. although I curse the pinhead-designer who put that period into IBM's language.
  64.  
  65. Following are examples of radix usage.  The numbers in the comments are all in
  66. decimal notation.
  67.  
  68.   DB 10,010     ; produces 10,16 if RADIX was not seen yet
  69. RADIX 10
  70.   DB 10,010     ; produces 10,10
  71. RADIX 16
  72.   DB 10,010     ; produces 16,16
  73. RADIX 2
  74.   DB 10,01010   ; produces 2,10
  75. RADIX 3         ; for Martian programmers in Heinlein novels
  76.   DB 10,100     ; produces 3,9
  77. RADIX
  78.   DB 10,010     ; produces 10,16
  79.  
  80.